package com.jiadakeji.ppm.common.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.StringTokenizer;

/**
 * http 工具类
 *
 * @Author xuelongjiang
 */
public class HttpUtils {


    /**
     * 获取用户真实IP
     * 如果有代理，获取真实客户端IP
     * @param request
     * @return
     */
    public  static  String getRealId(HttpServletRequest request){

        String xForwardedForHeader= request.getHeader("X-Forwarded-For");
        if(xForwardedForHeader == null){
            return  request.getRemoteAddr();

        }else {
            return  new StringTokenizer(xForwardedForHeader, ",").nextToken().trim();
        }

    }
}
